//数组的flatten 展平

//toString会去掉括号
console.log([1, [2, [3, [4, [5, [6]]]]]].toString()); //1,2,3,4,5,6
console.log([1, [2, [3, [4, [5, [6]]]]]].toString().split(',').map(item => parseInt(item)));


//
Array.prototype.myFlat = function (n = 1) {
  if(n === 0) {
    return this;
  }
  return this.reduce((a, b) => {
    if(Array.isArray(b)){
      return a.concat(b.myFlat(--n));
    }else{
      return [...a, b];
    }
  }, []);
};
let r = [1, [2, [3, [4, [5, [6]]]]]].myFlat(10); //展开几层
console.log(r);
